package visitor;

/**
 * 创建cpu供应商
 */
class CpuSupplier extends ComputerSupplier{

    @Override
    double getPrice() {
        return 1;
    }

    @Override
    void reception(Visitor_ v) {
        v.CpuVisitor(this);
    }
}
/**
 * 创建内存供应商
 */
class MemorySupplier extends ComputerSupplier{

    @Override
    double getPrice() {
        return 2;
    }

    @Override
    void reception(Visitor_ v) {
        v.MemoryVisitor(this);
    }
}

/**
 * 创建主板供应商
 */
class BoardSupplier extends ComputerSupplier{

    @Override
    double getPrice() {
        return 3;
    }

    @Override
    void reception(Visitor_ v) {
        v.BoardVisitor(this);
    }
}


/**
 * 装机城
 */
class ComputerCity{
    // 一定注意这个结构是死要是扩展很麻烦
    private ComputerSupplier cpu = new CpuSupplier();
    private ComputerSupplier board = new BoardSupplier();
    private ComputerSupplier mem = new MemorySupplier();

    void visitor(Visitor_ v){
        this.cpu.reception(v);
        this.board.reception(v);
        this.mem.reception(v);
    }
}

/**
 * 学生的渠道
 */
class Student extends Visitor_{

    @Override
    void CpuVisitor(ComputerSupplier c) {
        System.out.println(c.getPrice()*0.3+1);
    }

    @Override
    void BoardVisitor(ComputerSupplier c) {
        System.out.println(c.getPrice());
    }

    @Override
    void MemoryVisitor(ComputerSupplier c) {
        System.out.println(c.getPrice());
    }
}

public class Visitor {
    public static void main(String[] args) {
        System.out.println("visitor");


        ComputerCity computerCity = new ComputerCity();
        computerCity.visitor(new Student());

    }
}
